package com.food.restaurantpro.adapters;

import java.util.List;

import com.food.restaurantpro.objects.Reservation;
import com.food.restaurantpro.utils.AlertDialogInterface;
import com.food.restaurantpro.view.ReservationItemView;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ReservationArrayAdapter extends BaseAdapter {
	private final Activity mContext;
	private List<Reservation> mList;
	private AlertDialogInterface mCallBack;

	public ReservationArrayAdapter(Activity context, List<Reservation> list, AlertDialogInterface callback) {
		super();
		mList = list;
		this.mContext = context;
		this.mCallBack = callback;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Reservation reservation = mList.get(position);
		View view = null;

		// News view
		if (convertView == null) {
			view = new ReservationItemView(mContext, reservation, mCallBack);
		} else {
			view = convertView;
			((ReservationItemView)view).setReservationInfo(reservation);
		}
		((ReservationItemView)view).setupUI();
		return view;
	}

	@Override
	public int getCount() {
		return mList != null ? mList.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return mList != null ? mList.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	public List<Reservation> getList() {
		return mList;
	}
	
	public  void setList(List<Reservation> list) {
		this.mList = list;
	}
}
